package fyf.com.carddesign.main;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import fyf.com.carddesign.BaseActivity;
import fyf.com.carddesign.MyUtl.MyUtl;
import fyf.com.carddesign.R;

/**
 * Created by yxz on 2018/11/27.
 */

public class SelectActivity extends BaseActivity {
    @BindView(R.id.s_spinner)
    Spinner _spinner;
    List<String> tmpFileNames = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        initView();
    }


    private void initView() {
        File file = new File(MyUtl.SD_HOME_DIR);
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            tmpFileNames.add(files[i].getName());
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, tmpFileNames);
        _spinner.setAdapter(adapter);
        Log.d("yang_select", "我是spinner选中项：  " + _spinner.getSelectedItem().toString());
        _spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Log.d("yang_select", "我是spinner选中项：  " + _spinner.getSelectedItem().toString());
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }


    @OnClick(R.id.s_btn)
    public void nextBtnClick() {
        Intent intent = new Intent(this, CarToonActivity.class);
        intent.putExtra(MyUtl.PATH, _spinner.getSelectedItem().toString() + "/");
        startActivity(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.select;
    }
}
